﻿@model QuanLyGiaoVuUI.Models.SinhVien.DangKyDeTaiViewModel
@{
    Layout = "~/Views/Shared/_LayoutSinhVienClient2.cshtml";
}
@*   <style>
       table, table td, table tr {
           border:1px solid black;
           border-collapse:collapse;
       }
           table td {
               padding:5px;
           }
   </style>*@
<style>
    .gradeX a:hover {
        cursor:pointer;
    }
</style>

@if (Model.SinhVienDeTai.DeTaiSinhVien != null)
{
    <br />
    <br />
    <div><h4>ĐỀ TÀI SINH VIÊN ĐÃ ĐĂNG KÝ</h4></div>
    <table class="data display datatable">
        <tr>
            <th class="sorting">Tên Đề Tài</th>
            <th class="sorting">STT</th>
            <th class="sorting">Giảng Viên HD</th>            
            <th class="sorting">Số ĐT Liên Hệ</th>
        </tr>
        @if (Model.SinhVienDeTai.GiangVien1 != null)
        {
            <tr class="gradeA odd">                
                <td rowspan="2" class="odd gradeX">@Model.SinhVienDeTai.DeTaiSinhVien.TenDeTai</td>
                <td>1</td>
                <td class="odd gradeX">@Model.SinhVienDeTai.GiangVien1.HoTenGV</td>
                <td class="odd gradeX"> @Model.SinhVienDeTai.GiangVien1.SoDienThoai</td>
            </tr>
        }
        @if (Model.SinhVienDeTai.GiangVien2 != null)
        {
            <tr class="gradeA even">
                <td>2</td>
                <td class="odd gradeX">@Model.SinhVienDeTai.GiangVien2.HoTenGV</td>
                <td class="odd gradeX">@Model.SinhVienDeTai.GiangVien2.SoDienThoai</td>
            </tr>
        }
    </table>
    <br />
}

@if (Model.SinhVienDeTai.SinhVien1 != null)
{
    <div>
        <h4>SINH VIÊN THỰC HIỆN</h4>
    </div>
    <table class="data display datatable">
        <tr>
            <th class="sorting">STT</th>
            <th class="sorting">Họ Tên</th>
            <th class="sorting">MSSV</th>
            <th class="sorting">Giới Tính</th>
            <th class="sorting">Ngày Sinh</th>
        </tr>
        <tr class="gradeA even">
            <td class="even gradeX">1</td>
            <td class="even gradeX">@Model.SinhVienDeTai.SinhVien1.HoTenSV</td>
            <td class="even gradeX">@Model.SinhVienDeTai.SinhVien1.MaSinhVien</td>
            @if (@Model.SinhVienDeTai.SinhVien1.GioiTinh == 1)
            {
                <td class="even gradeX">Nam</td>
            }
            else
            {
                <td class="even gradeX">Nữ</td>
            }
            <td class="even gradeX">@Model.SinhVienDeTai.SinhVien1.NgaySinh.ToShortDateString()</td>            
        </tr>
        @if (Model.SinhVienDeTai.SinhVien2 != null)
        {
            <tr class="gradeA odd">
                <td class="odd gradeX">2</td>
                <td class="odd gradeX">@Model.SinhVienDeTai.SinhVien2.HoTenSV</td>
                <td class="odd gradeX">@Model.SinhVienDeTai.SinhVien2.MaSinhVien</td>
                @if (@Model.SinhVienDeTai.SinhVien2.GioiTinh == 1)
                {
                    <td class="odd gradeX">Nam</td>
                }
                else
                {
                    <td class="odd gradeX">Nữ</td>
                }
                <td class="odd gradeX">@Model.SinhVienDeTai.SinhVien2.NgaySinh.ToShortDateString()</td>
            </tr>
        }
    </table>
}
<br />
<br />
<br />
<div>
    <h4>
        DANH SÁCH ĐỀ TÀI NĂM HỌC: @if (Model.NamHoc != null){ <span>@Model.NamHoc.Nam1</span> <span>-</span> <span>@Model.NamHoc.Nam2</span> }
    </h4>
</div>
<br />
<div>
    <table class="data display datatable">
        <tr>
            <th class="sorting">STT</th>
            <th class="sorting">Tên Đề Tài</th>
            <th class="sorting">Mô tả</th>
            <th class="sorting">Giảng Viên 1</th>
            <th class="sorting">Giảng Viên 2</th>
            <th class="sorting" style="width: 60px;">Đăng Ký</th>
        </tr>
        @if (Model.DanhSachDeTaiNamHoc != null)
        {
            int stt = 1;
            int count = 1;
            foreach (var detai in Model.DanhSachDeTaiNamHoc)
            {
                if( detai.DatYeuCau==true)
                {
                bool isHas = false;
            <tr class="gradeA @(++count % 2 == 0 ? "even" : "odd")">
                @if (Model.DanhSachDeTaiDaDangKy != null)
                {                
                         
                    <td class="odd gradeX">@stt</td>    
                    <td class="odd gradeX" >@detai.TenDeTai</td>                   
                    <td class="odd gradeX">@Html.Raw(detai.MoTa)</td>
                    <td class="odd gradeX">@detai.GiangVien1.HoTenGV</td>
                    <td class="odd gradeX">@detai.GiangVien2.HoTenGV</td>
                    foreach (var dadangky in Model.DanhSachDeTaiDaDangKy)
                    {
                        if (dadangky.MaDeTai == detai.MaDeTai)
                        {
                            isHas = true;
                            break;
                        }
                    }
                }
                @if (isHas == false)
                {                         
                    <td class="odd gradeX"><a class="dangky" rel="@detai.MaDeTai">[Đăng Ký]</a></td>                 
                }
                else
                {                                       
                    <td id="dadkdetai" class="odd gradeX"><a id="huydangkydetai" rel="@detai.MaDeTai">[Huỷ]</a></td>
                }
            </tr>
                stt++;
                }
            }
        }
    </table>
</div>
<script type="text/javascript" src="/Scripts/jquery-1.8.2.js"></script>
<script type="text/javascript" src="/Scripts/jquery-ui.js"></script>
<script type="text/javascript" src="/Scripts/jquery.unobtrusive-ajax.min.js"></script>

<script type="text/javascript" src="@Url.Content("~/Content/js/jsToastMessage/javascript/jquery.toastmessage.js")"></script>

<div id="dangKyDeTaiDialog"></div>
<div id="huyDangKyDeTaiDialog"></div>
<script>
    $(document).ready(function () {
        $('#dadkdetai').parent().css({ "color": "red", "font-weight": "bold" });
        $("#dangKyDeTaiDialog").load("/SinhVien/DangKyDeTai");
        $("#huyDangKyDeTaiDialog").load("/SinhVien/HuyDangKyDeTai");
        $("#dangKyDeTaiDialog").dialog({
            autoOpen: false, modal: true, width: 500, height: "auto", title: "Đăng ký đề tài",
            buttons: {
                "Đăng Ký": function () {
                    $("#btnDangKyDeTai").click();
                },
                "Hủy": function () {
                    $("#dangKyDeTaiDialog").dialog("close");
                }
            }
        });
        $("#huyDangKyDeTaiDialog").dialog({
            autoOpen: false, modal: true, width: 500, height: "auto", title: "Hủy đăng ký đề tài!",
            buttons: {
                "Tiếp tục": function () {
                    $("#btnHuyDangKyDeTai").click();
                },
                "Không": function () {
                    $("#huyDangKyDeTaiDialog").dialog("close");
                }
            }
        });
        $('.dangky').click(function () {
            var madetai = $(this).attr("rel");
            $("#madetaidk").attr("value", madetai);
            $("#dangKyDeTaiDialog").dialog("open");
        });
        $('#huydangkydetai').click(function () {
            var madetai = $(this).attr("rel");
            //alert(madetai);
            $("#madetaihuydk").attr("value", madetai);
            $("#huyDangKyDeTaiDialog").dialog("open");
        });
    });
    function DangKyThanhCong(data) {
        //if (data.message != null) {
        //    //alert(data.message);                        
        //}
        //if (data.success == true) {
        //    $("#dangKyDeTaiDialog").dialog("close");
        //    window.location = "/SinhVien/XemDeTaiDangKy";
        //}        
        
        ThongBao(data, "/SinhVien/XemDeTaiDangKy");
    }
    function HuyDangKyDeTai(data) {
        //if (data.message != null)
        //    alert(data.message);
        //if (data.success == true) {
        //    $("#huyDangKyDeTaiDialog").dialog("close");
        //}
        //window.location = "/SinhVien/XemDeTaiDangKy";
        ThongBao(data, "/SinhVien/XemDeTaiDangKy");
    }

    function ThongBao(data, url) {
        if (data.success) {            
            ToastManager.showSuccessToast(data.message);
            setTimeout(function () {
                refreshPage(url);
            }, 2000);
        }
        else {
            ToastManager.showStickyWarningToast(data.message);
        }
    }
    function refreshPage(url) {
        window.location = url;
    }
</script>
